<?php
namespace app\auth\controller;

use think\Controller;
use \think\Db;
use app\api\controller\v2\Auth;

class Base extends Auth
{
//    public function _initialize()
//    {
//        if(!defined('IS_ACCESS_TOKEN_CHECKED'))
//        {
//            // 接口调用验证
//            $check = $this->checkAuth();
//
//            if($check['code'] != 200)
//            {
//                echo json_encode($check);
//                exit;
//            }
//        }
//    }

    protected function checkAuth()
    {
        $access_token = privDecrypt(input('access_token'));

        if(!$access_token)
        {
            return ['code'=>10107,'msg'=>'访问凭证不存在'];
        }

        $data = Db::table('app_appid') -> where("`app_accesstoken`='$access_token'") -> find();

        if(empty($data) || $data['app_expire'] + $data['app_gettime'] < time())
        {
            return ['code'=>10108,'msg'=>'访问凭证过期'];
        }

        if($data['app_status'] != 1)
        {
            return ['code'=>10109,'msg'=>'禁止访问'];
        }
        define('IS_ACCESS_TOKEN_CHECKED',true);

        return ['code'=>200,'msg'=>'成功'];
    }

}